﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Data.SqlClient;

namespace RLZY
{
    public partial class FormGL_JT_Modify : Form
    {
        public FormGL_JT_Modify()
        {
            InitializeComponent();
        }
        private static FormGL_JT_Modify childFromInstanc;
        static log4net.ILog LOG = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        public String userID;
        public String 权限;


        public static FormGL_JT_Modify ChildFromInstanc
        {
            get
            {
                if (childFromInstanc == null || childFromInstanc.IsDisposed)
                //判断childFromInstanc是否有值，不为null或者窗体释放（当你将子窗体关了的时候）为childFromInstanc赋值
                {
                    childFromInstanc = new FormGL_JT_Modify();
                }
                return childFromInstanc;
                //返回的childFromInstanc（子窗体存在时返回的是null,关闭了（IsDisposed为true）或者第一次打开子窗体返回一个ChildForm实例）
            }
        }

        private void FormGZBH_Load(object sender, EventArgs e)
        {
            this.Date0 = DateTime.Now.AddDays((double)(0 - DateTime.Now.Day + 1));
            this.date2 = DateTime.Now.AddDays((double)(0 - DateTime.Now.Day + 32));
        }
        public bool ISSafe()
        {
            others.safe sa = new others.safe();
            SqlDataReader re = sa.GetDateSafe(this.dtpDateEnd.Text);
            if (re.Read())
            { return true; }
            else { return false; }

        }

        public DateTime Date0 { get; set; }

        public DateTime date2 { get; set; }

        private void btnOK_Click(object sender, EventArgs e)
        {
            //others.safe safe = new others.safe();
            
           
            //    MessageBox.Show(safe.modify(this.dtpDateEnd.Text).ToString());

            try
            {
                if (!ISSafe())
                {
                    if (this.GZ_JT_Modify())
                    {
                        MessageBox.Show("调整工龄津贴完毕");
                    }
                    else
                    {
                        MessageBox.Show("无任何数据调整");
                    }

                }
                else { MessageBox.Show("本月已做保护及初始化，不能调整工龄津贴"); }
            }
            catch (Exception ex) { LOG.Error(ex); }
        }

        public bool GZ_JT_Modify()
        {
            others.safe safe = new others.safe();
            safe.set0TONull();
            
            if (safe.modify(this.dtpDateEnd.Text) > 0)
            {
                return true;
            }
            else { return false; }


           
        }
    }
}
